import { Getcate } from "../../http/api"

const initState = {
    //初始化数据
    //左
    cate: [],
    //右
    catelist: [],
    n: 0,
    fid: "",
    idArr: []
}
const  TYPES = {
    CATE_CHANGE_CATE:"CATE_CHANGE_CATE",
    CATE_CHANGE_CATELIST:'CATE_CHANGE_CATELIST',
    CATE_CHANGE_N:"CATE_CHANGE_N",

}
export const actions = {
    changeGetnate:cate => ({
        type:TYPES.CATE_CHANGE_CATE,
        cate
    }),
    reqCatelist:()=>{
        return  async (dispatch,getState)=>{
            let res = await Getcate()
            if (res.data.code === 200) {
                dispatch(actions.changeGetnate(res.data.list))
            }
        }
    }
}
export const cateReducer = (state = initState,action) =>{
    switch (action.type) {
        case TYPES.CATE_CHANGE_CATE:
            return{
                ...state,
                cate:action.cate
            }
        default:
            return state;
    }
}
export const getcate = state => state.cate.cate;